home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.awt;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.LayoutManager;
- import java.awt.Panel;
- import java.awt.TextField;
-
- public class ComboBox extends Panel {
- public static final int EVT_IMAGE_SELECT = 16388;
- private boolean bEditable;
- private boolean bSearchable;
- private boolean bCaseSensitive;
- private TextField editBox;
- private DirectionButton arrow;
- private ImageListBox list;
- private boolean bDown;
- // $FF: renamed from: ix int
- private int field_0;
- // $FF: renamed from: iy int
- private int field_1;
- private int iwidth;
- private int iheight;
- private int lheight;
- private boolean bOverList;
- private boolean showHScroll;
- private boolean showVScroll;
- private Font editFont;
- private Font dropFont;
- private static boolean bOsFlag;
- private static ComboBox currentlyDown = null;
- private Component parent;
- private String sSearchText;
- private String sSearchItem;
- private String sLastText;
- private String sSearchOrig;
- private int searchIndex;
- private int searchLen;
- private int searchI;
-
- public ComboBox() {
- this(false, false);
- }
-
- public ComboBox(boolean var1, boolean var2) {
- this.bDown = false;
- this.bOverList = false;
- this.showHScroll = false;
- this.showVScroll = true;
- bOsFlag = !System.getProperty("os.name").startsWith("Win");
- ((Container)this).setLayout((LayoutManager)null);
- this.editBox = new TextField("");
- this.editBox.setBackground(Color.white);
- this.arrow = new DirectionButton(3);
- this.list = new ImageListBox("ILB");
- this.list.setComboMode(true);
- this.list.setShowHorizontalScroll(false);
- ((Container)this).add(this.list);
- ((Container)this).add(this.editBox);
- ((Container)this).add(this.arrow);
- this.arrow.setShowFocus(false);
- this.arrow.shrinkTriangle(1, 1, 5, 5);
- this.arrow.disable();
- this.lheight = 0;
- this.list.hide();
- this.setEditable(var1);
- this.setSearchable(var2);
- this.bCaseSensitive = true;
- }
-
- public void setEditable(boolean var1) {
- this.bEditable = var1;
- this.editBox.setEditable(this.bEditable || this.bSearchable);
- }
-
- public boolean getEditable() {
- return this.bEditable;
- }
-
- public void setSearchable(boolean var1) {
- this.bSearchable = var1;
- this.editBox.setEditable(this.bEditable || this.bSearchable);
- }
-
- public boolean getSearchable() {
- return this.bSearchable;
- }
-
- public void setCaseSensitive(boolean var1) {
- this.bCaseSensitive = var1;
- }
-
- public boolean getCaseSensitive() {
- return this.bCaseSensitive;
- }
-
- public void setShowHorizontalScroll(boolean var1) {
- this.showHScroll = var1;
- this.list.setShowHorizontalScroll(var1);
- }
-
- public boolean getShowHorizontalScroll() {
- return this.showHScroll;
- }
-
- public void setShowVerticalScroll(boolean var1) {
- this.showVScroll = var1;
- this.list.setShowVerticalScroll(var1);
- }
-
- public boolean getShowVerticalScroll() {
- return this.showVScroll;
- }
-
- public synchronized void setComboBoxFont(Font var1) {
- this.setFont(var1);
- }
-
- public synchronized Font getComboBoxFont() {
- return this.editFont;
- }
-
- public synchronized void setEditFieldFont(Font var1) {
- if (this.editBox != null && var1 != null && this.iheight > 15) {
- this.editFont = var1;
- this.editBox.setFont(var1);
- }
-
- }
-
- public synchronized Font getEditFieldFont() {
- return this.editFont;
- }
-
- public synchronized void setDropDownFont(Font var1) {
- if (this.list != null && var1 != null) {
- this.dropFont = var1;
- this.list.setFont(var1);
- }
-
- }
-
- public synchronized Font getDropDownFont() {
- return this.dropFont;
- }
-
- public boolean handleEvent(Event var1) {
- switch (var1.id) {
- case 401:
- this.sLastText = this.editBox.getText();
- break;
- case 402:
- if (var1.target == this.editBox) {
- this.verify();
- }
- break;
- case 404:
- if (var1.target != this.editBox) {
- switch (var1.key) {
- case 1000:
- this.list.select(0);
- break;
- case 1001:
- this.list.select(this.list.countItems() - 1);
- break;
- case 1002:
- case 1004:
- this.list.select(this.list.getSelectedIndex() - 1);
- break;
- case 1003:
- case 1005:
- this.list.select(this.list.getSelectedIndex() + 1);
- }
-
- this.editBox.setText(this.list.getSelectedItem());
- this.editBox.selectAll();
- }
- break;
- case 504:
- if (var1.target == this.list) {
- this.bOverList = true;
- }
- break;
- case 505:
- if (var1.target == this.list) {
- this.bOverList = false;
- }
- break;
- case 701:
- this.editBox.setText(this.list.getSelectedItem());
- if (this.parent == null) {
- this.parent = ((Component)this).getParent();
- }
-
- if (this.parent != null) {
- var1.target = this;
- var1.id = 1001;
- this.parent.postEvent(var1);
- }
-
- this.dropList(false);
- return true;
- case 1001:
- if (var1.target instanceof DirectionButton) {
- this.dropList(!this.bDown);
- return true;
- }
-
- if (var1.target == this.list) {
- return true;
- }
- break;
- case 1004:
- if (var1.target == this && !this.bDown) {
- this.editBox.selectAll();
- this.editBox.requestFocus();
- } else if (bOsFlag && var1.target == this.editBox) {
- this.dropList(false);
- }
- break;
- case 1005:
- if (var1.target == this.arrow && !this.bOverList) {
- this.dropList(false);
- }
- break;
- case 16388:
- if (this.parent == null) {
- this.parent = ((Component)this).getParent();
- }
-
- if (this.parent != null) {
- var1.target = this;
- this.parent.postEvent(var1);
- }
-
- return true;
- }
-
- return super.handleEvent(var1);
- }
-
- public static boolean addFirstTopDown() {
- return !addLastBottomUp();
- }
-
- public static boolean addLastBottomUp() {
- String var0 = System.getProperty("os.name");
- if (!var0.startsWith("S") && !var0.startsWith("Kona") && !var0.startsWith("AIX") && !var0.startsWith("OSF")) {
- return var0.startsWith("Win") && System.getProperty("java.vendor").startsWith("Netscape") && System.getProperty("java.version").equals("1.02");
- } else {
- return true;
- }
- }
-
- public static boolean needsPlatformHelp() {
- return bOsFlag;
- }
-
- public static void unDropLastDropped() {
- if (currentlyDown != null) {
- currentlyDown.dropList(false);
- }
-
- }
-
- public void clear() {
- this.list.clear();
- this.editBox.setText("");
- }
-
- public synchronized void addItem(String var1) {
- this.addItem((Image)null, var1, true);
- }
-
- public synchronized void addItem(String var1, boolean var2) {
- this.addItem((Image)null, var1, var2);
- }
-
- public synchronized void addItem(Image var1, String var2) {
- this.addItem(var1, var2, true);
- }
-
- public synchronized void addItem(Image var1, String var2, boolean var3) {
- this.list.addItem(var1, var2, var3);
- this.arrow.enable();
- }
-
- public void setListItems(String[] var1) {
- this.clear();
-
- for(int var2 = 0; var2 < var1.length; ++var2) {
- this.addItem(var1[var2]);
- }
-
- }
-
- public String[] getListItems() {
- int var1 = this.countItems();
- String[] var2 = new String[var1];
-
- for(int var3 = 0; var3 < var1; ++var3) {
- var2[var3] = this.getItem(var3);
- }
-
- return var2;
- }
-
- public int countItems() {
- return this.list.countItems();
- }
-
- public String getItem(int var1) {
- return this.list.getItem(var1);
- }
-
- public void changeImage(int var1, Image var2) {
- this.list.changeImage(var1, var2);
- }
-
- public void changeText(int var1, String var2) {
- this.list.changeText(var1, var2);
- }
-
- public void enable(int var1) {
- this.list.enable(var1);
- }
-
- public void disable(int var1) {
- this.list.disable(var1);
- }
-
- public void enable(int var1, boolean var2) {
- if (var2) {
- this.list.enable(var1);
- } else {
- this.list.disable(var1);
- }
- }
-
- public synchronized void delItem(int var1) {
- this.delItems(var1, var1);
- }
-
- public synchronized void delItems(int var1, int var2) {
- this.list.delItems(var1, var2);
- if (this.list.countItems() == 0) {
- this.arrow.disable();
- this.dropList(false);
- }
-
- }
-
- public synchronized void delSelectedItem() {
- this.list.delSelectedItems();
- }
-
- public String getText() {
- this.verify();
- return this.editBox.getText();
- }
-
- public String getSelectedItem() {
- return this.list.getSelectedItem();
- }
-
- public int getSelectedIndex() {
- return this.list.getSelectedIndex();
- }
-
- public synchronized void select(int var1) {
- if (var1 >= 0 && var1 <= this.list.countItems()) {
- this.list.select(var1);
- this.editBox.setText(this.list.getSelectedItem());
- if (bOsFlag) {
- ((Component)this).repaint();
- }
- }
-
- }
-
- public void select(String var1) {
- this.list.select(var1);
- this.editBox.setText(this.list.getSelectedItem());
- if (bOsFlag) {
- ((Component)this).repaint();
- }
-
- }
-
- public synchronized void deselect(int var1) {
- this.list.deselect(var1);
- }
-
- public synchronized boolean isSelected(int var1) {
- return this.list.isSelected(var1);
- }
-
- public synchronized void setFont(Font var1) {
- this.editFont = this.dropFont = var1;
- this.setEditFieldFont(var1);
- this.setDropDownFont(var1);
- super.setFont(var1);
- }
-
- public void dropList(boolean var1) {
- if (this.bDown != var1) {
- this.bDown = var1;
- if (var1) {
- if (currentlyDown != null && currentlyDown != this) {
- currentlyDown.dropList(false);
- }
-
- currentlyDown = this;
- this.list.show();
- this.list.setDirty();
- this.list.repaint();
- if (((Component)this).getParent() != null) {
- this.lheight = Math.min(((Component)this).getParent().bounds().height - this.field_1 - this.iheight - 10, this.list.minimumSize().height + 3);
- } else {
- this.lheight = this.list.minimumSize().height + 3;
- }
-
- this.arrow.setDirection(2);
- } else {
- this.lheight = 0;
- currentlyDown = null;
- this.list.hide();
- this.arrow.setDirection(3);
- ((Component)this).invalidate();
- }
-
- this.arrow.repaint();
- super.reshape(this.field_0, this.field_1, this.iwidth, this.iheight + this.lheight);
- }
- }
-
- public synchronized void reshape(int var1, int var2, int var3, int var4) {
- this.field_0 = var1;
- this.field_1 = var2;
- this.iwidth = var3;
- if (bOsFlag) {
- this.iheight = Math.max(29, var4);
- } else {
- this.iheight = var4;
- }
-
- if (var4 > 22) {
- var4 -= 22;
- if (bOsFlag) {
- var2 = 7;
- var1 = 7;
- } else {
- var2 = 5;
- var1 = 5;
- }
-
- while(var4 > 0) {
- ++var1;
- --var4;
- if (var4 > 0) {
- ++var2;
- --var4;
- }
- }
-
- this.arrow.shrinkTriangle(1, 1, var1, var2);
- } else {
- this.arrow.shrinkTriangle(1, 1, 5, 5);
- }
-
- super.reshape(this.field_0, this.field_1, this.iwidth, this.iheight + this.lheight);
- }
-
- public void paint(Graphics var1) {
- super.paint(var1);
- Dimension var2 = ((Component)this).size();
- if (this.bDown) {
- this.list.reshape(0, this.iheight + 1, var2.width, this.lheight);
- }
-
- this.editBox.reshape(0, 0, var2.width - 16, this.iheight);
- if (bOsFlag) {
- this.arrow.reshape(var2.width - 16, 2, 15, this.iheight - 4);
- } else {
- this.arrow.reshape(var2.width - 16, 1, 15, this.iheight - 2);
- }
- }
-
- public Dimension preferredSize() {
- Dimension var1 = ((Component)this).size();
- Dimension var2 = this.minimumSize();
- return new Dimension(Math.max(var1.width, var2.width), Math.max(var1.height, var2.height));
- }
-
- public Dimension minimumSize() {
- Dimension var1 = this.editBox.minimumSize();
- var1.width += 17;
- if (var1.height == 0) {
- if (bOsFlag) {
- var1.height = 29;
- } else {
- var1.height = 21;
- }
- }
-
- return var1;
- }
-
- private void verify() {
- if (this.bSearchable) {
- this.searchIndex = this.editBox.getSelectionStart();
- this.sSearchOrig = this.editBox.getText().substring(0, this.searchIndex);
- if (this.bCaseSensitive) {
- this.sSearchText = this.sSearchOrig;
- } else {
- this.sSearchText = this.sSearchOrig.toUpperCase();
- }
-
- this.searchLen = this.list.countItems();
- if (this.sSearchText.length() > 0) {
- for(this.searchI = 0; this.searchI < this.searchLen; ++this.searchI) {
- if (this.bCaseSensitive) {
- this.sSearchItem = this.list.getItem(this.searchI);
- } else {
- this.sSearchItem = this.list.getItem(this.searchI).toUpperCase();
- }
-
- if (this.sSearchItem.startsWith(this.sSearchText)) {
- this.editBox.setText(this.sSearchOrig);
- this.list.select(this.searchI);
- this.editBox.select(this.searchIndex, this.searchIndex);
- break;
- }
- }
-
- if (!this.bEditable && this.searchI == this.searchLen) {
- this.editBox.setText(this.sLastText);
- this.editBox.select(this.searchIndex - 1, this.searchIndex - 1);
- }
- }
- }
-
- this.sLastText = this.editBox.getText();
- }
- }
-